package www.xfOnline.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;

import www.xfOnline.bean.User;
import www.xfOnline.dao.JDBCDAO;
import www.xfOnline.util.DatePickerTool;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class FixPersonDataFrame extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JPasswordField passwordField;
	private DatePickerTool datePicker;
	private JComboBox comboBox;
	private ButtonGroup bg ;
	private JRadioButton bgril;
	private JRadioButton bboy;
	/**
	 * Create the frame.
	 */
	public FixPersonDataFrame(User user) {
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		Dimension scressSize = getToolkit().getScreenSize();
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds((int)scressSize.getWidth()/3, (int)scressSize.getHeight()/4, (int)scressSize.getWidth()/3, (int)scressSize.getHeight()/4*2);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_contentPane.columnWeights = new double[]{0.0, 2.0, 1.0,1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		JPanel panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 0);
		gbc_panel.gridwidth = 4;
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 0;
		contentPane.add(panel, gbc_panel);
		
		JLabel lblNewLabel = new JLabel("资料修改");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
		panel.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("账号");
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 1;
		gbc_lblNewLabel_1.gridy = 1;
		contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
		
		textField = new JTextField();
		textField.setText(String.valueOf(user.getAccount()));
		textField.setEditable(false);
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 2;
		gbc_textField.gridy = 1;
		contentPane.add(textField, gbc_textField);
		textField.setColumns(10);
		
		JLabel Label_1 = new JLabel("");
		GridBagConstraints gbc_Label_1 = new GridBagConstraints();
		gbc_Label_1.insets = new Insets(0, 0, 5, 0);
		gbc_Label_1.gridx = 3;
		gbc_Label_1.gridy = 1;
		contentPane.add(Label_1, gbc_Label_1);
		
		JLabel lblNewLabel_2 = new JLabel("名字");
		GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
		gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_2.gridx = 1;
		gbc_lblNewLabel_2.gridy = 2;
		contentPane.add(lblNewLabel_2, gbc_lblNewLabel_2);
		
		textField_1 = new JTextField();
		textField_1.setText(user.getName());
		System.out.println(user.getName());
		GridBagConstraints gbc_textField_1 = new GridBagConstraints();
		gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_1.insets = new Insets(0, 0, 5, 5);
		gbc_textField_1.gridx = 2;
		gbc_textField_1.gridy = 2;
		contentPane.add(textField_1, gbc_textField_1);
		textField_1.setColumns(10);
		
		JLabel Label_2 = new JLabel("");
		GridBagConstraints gbc_Label_2 = new GridBagConstraints();
		gbc_Label_2.insets = new Insets(0, 0, 5, 0);
		gbc_Label_2.gridx = 3;
		gbc_Label_2.gridy = 2;
		contentPane.add(Label_2, gbc_Label_2);
		
		JLabel lblNewLabel_3 = new JLabel("密码");
		GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
		gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_3.gridx = 1;
		gbc_lblNewLabel_3.gridy = 3;
		contentPane.add(lblNewLabel_3, gbc_lblNewLabel_3);
		
		passwordField = new JPasswordField();
		passwordField.setText("12345678");
		passwordField.setEnabled(false);
		GridBagConstraints gbc_passwordField = new GridBagConstraints();
		gbc_passwordField.fill = GridBagConstraints.HORIZONTAL;
		gbc_passwordField.insets = new Insets(0, 0, 5, 5);
		gbc_passwordField.gridx = 2;
		gbc_passwordField.gridy = 3;
		contentPane.add(passwordField, gbc_passwordField);
		
		JButton button_2 = new JButton("修改密码");
		GridBagConstraints gbc_button_2 = new GridBagConstraints();
		gbc_button_2.insets = new Insets(0, 0, 5, 0);
		gbc_button_2.gridx = 3;
		gbc_button_2.gridy = 3;
		contentPane.add(button_2, gbc_button_2);
		
		
		
		JLabel lblNewLabel_4 = new JLabel("手机");
		GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
		gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_4.gridx = 1;
		gbc_lblNewLabel_4.gridy = 4;
		contentPane.add(lblNewLabel_4, gbc_lblNewLabel_4);
		
		textField_3 = new JTextField();
		textField_3.setText(user.getTel());
		textField_3.setEnabled(false);
		GridBagConstraints gbc_textField_3 = new GridBagConstraints();
		gbc_textField_3.insets = new Insets(0, 0, 5, 5);
		gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_3.gridx = 2;
		gbc_textField_3.gridy = 4;
		contentPane.add(textField_3, gbc_textField_3);
		textField_3.setColumns(10);
		
		JButton button = new JButton("修改手机");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		GridBagConstraints gbc_button = new GridBagConstraints();
		gbc_button.insets = new Insets(0, 0, 5, 0);
		gbc_button.gridx = 3;
		gbc_button.gridy = 4;
		contentPane.add(button, gbc_button);
		
		
		
		JLabel lblNewLabel_5 = new JLabel("QQ");
		GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
		gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_5.gridx = 1;
		gbc_lblNewLabel_5.gridy = 5;
		contentPane.add(lblNewLabel_5, gbc_lblNewLabel_5);
		
		textField_4 = new JTextField();
		textField_4.setText(user.getQq());
		GridBagConstraints gbc_textField_4 = new GridBagConstraints();
		gbc_textField_4.insets = new Insets(0, 0, 5, 5);
		gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_4.gridx = 2;
		gbc_textField_4.gridy = 5;
		contentPane.add(textField_4, gbc_textField_4);
		textField_4.setColumns(10);
		
		JLabel Label_5 = new JLabel("");
		GridBagConstraints gbc_Label_5 = new GridBagConstraints();
		gbc_Label_5.insets = new Insets(0, 0, 5, 0);
		gbc_Label_5.gridx = 3;
		gbc_Label_5.gridy = 5;
		contentPane.add(Label_5, gbc_Label_5);
		
		JLabel lblNewLabel_6 = new JLabel("email");
		GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
		gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_6.gridx = 1;
		gbc_lblNewLabel_6.gridy = 6;
		contentPane.add(lblNewLabel_6, gbc_lblNewLabel_6);
		
		textField_5 = new JTextField();
		textField_5.setText(user.getEmail());
		textField_5.setEnabled(false);
		GridBagConstraints gbc_textField_5 = new GridBagConstraints();
		gbc_textField_5.insets = new Insets(0, 0, 5, 5);
		gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_5.gridx = 2;
		gbc_textField_5.gridy = 6;
		contentPane.add(textField_5, gbc_textField_5);
		textField_5.setColumns(10);
		
		JButton button_1 = new JButton("修改邮箱");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		GridBagConstraints gbc_button_1 = new GridBagConstraints();
		gbc_button_1.insets = new Insets(0, 0, 5, 0);
		gbc_button_1.gridx = 3;
		gbc_button_1.gridy = 6;
		contentPane.add(button_1, gbc_button_1);
		
		
		JLabel lblNewLabel_7 = new JLabel("地址");
		GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
		gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_7.gridx = 1;
		gbc_lblNewLabel_7.gridy = 7;
		contentPane.add(lblNewLabel_7, gbc_lblNewLabel_7);
		
		textField_6 = new JTextField();
		textField_6.setText(user.getAddress());
		GridBagConstraints gbc_textField_6 = new GridBagConstraints();
		gbc_textField_6.insets = new Insets(0, 0, 5, 5);
		gbc_textField_6.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_6.gridx = 2;
		gbc_textField_6.gridy = 7;
		contentPane.add(textField_6, gbc_textField_6);
		textField_6.setColumns(10);
		
		JLabel Label_7 = new JLabel("");
		GridBagConstraints gbc_Label_7 = new GridBagConstraints();
		gbc_Label_7.insets = new Insets(0, 0, 5, 0);
		gbc_Label_7.gridx = 3;
		gbc_Label_7.gridy = 7;
		contentPane.add(Label_7, gbc_Label_7);
		
		JLabel lblNewLabel_8 = new JLabel("性别");
		GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
		gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_8.gridx = 1;
		gbc_lblNewLabel_8.gridy = 8;
		contentPane.add(lblNewLabel_8, gbc_lblNewLabel_8);
		
		JPanel panel_1 = new JPanel();
		bg = new ButtonGroup();
		bboy = new JRadioButton();
		bboy.setToolTipText("男");
		bgril = new JRadioButton();
		bgril.setToolTipText("女");
		bg.add(bboy);
		bg.add(bgril);
		panel_1.add(bboy);
		if(user.getSex().toString().equals("男")){
			bboy.setSelected(true);
		}else{
			bgril.setSelected(true);
		}
		
		JLabel label = new JLabel("男");
		panel_1.add(label);
		panel_1.add(bgril);
		
		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
		gbc_panel_1.insets = new Insets(0, 0, 5, 5);
		gbc_panel_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_1.gridx = 2;
		gbc_panel_1.gridy = 8;
		contentPane.add(panel_1, gbc_panel_1);
		
		JLabel label_1 = new JLabel("女");
		panel_1.add(label_1);
		
		JLabel Label_8 = new JLabel("");
		GridBagConstraints gbc_Label_8 = new GridBagConstraints();
		gbc_Label_8.insets = new Insets(0, 0, 5, 0);
		gbc_Label_8.gridx = 3;
		gbc_Label_8.gridy = 8;
		contentPane.add(Label_8, gbc_Label_8);
		
		JLabel lblNewLabel_9 = new JLabel("出生日期");
		GridBagConstraints gbc_lblNewLabel_9 = new GridBagConstraints();
		gbc_lblNewLabel_9.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_9.gridx = 1;
		gbc_lblNewLabel_9.gridy = 9;
		contentPane.add(lblNewLabel_9, gbc_lblNewLabel_9);
		
		JPanel panel_date = new JPanel(new BorderLayout());
		GridBagConstraints gbc_panel_date = new GridBagConstraints();
		gbc_panel_date.insets = new Insets(0, 0, 5, 5);
		gbc_panel_date.fill = GridBagConstraints.BOTH;
		gbc_panel_date.gridx = 2;
		gbc_panel_date.gridy = 9;
		contentPane.add(panel_date, gbc_panel_date);
		datePicker = new DatePickerTool(user.getBirth());
		panel_date.add(datePicker,BorderLayout.CENTER);
		
		JLabel Label_9 = new JLabel("");
		GridBagConstraints gbc_Label_9 = new GridBagConstraints();
		gbc_Label_9.insets = new Insets(0, 0, 5, 0);
		gbc_Label_9.gridx = 3;
		gbc_Label_9.gridy = 9;
		contentPane.add(Label_9, gbc_Label_9);

		JLabel lblNewLabel_11 = new JLabel("血型");
		GridBagConstraints gbc_lblNewLabel_11 = new GridBagConstraints();
		gbc_lblNewLabel_11.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_11.gridx = 1;
		gbc_lblNewLabel_11.gridy = 10;
		contentPane.add(lblNewLabel_11, gbc_lblNewLabel_11);
		
		comboBox = new JComboBox();                    //不能用
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"O", "A", "B", "AB","其他"}));
		comboBox.setSelectedIndex(getBloodIndex(user.getBlood().toString()));   
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 2;
		gbc_comboBox.gridy = 10;
		contentPane.add(comboBox, gbc_comboBox);
		
		JLabel Label_10 = new JLabel("");
		GridBagConstraints gbc_Label_10 = new GridBagConstraints();
		gbc_Label_10.insets = new Insets(0, 0, 5, 0);
		gbc_Label_10.gridx = 3;
		gbc_Label_10.gridy = 10;
		contentPane.add(Label_10, gbc_Label_10);
		
		JLabel lblNewLabel_10 = new JLabel("学校");
		GridBagConstraints gbc_lblNewLabel_10 = new GridBagConstraints();
		gbc_lblNewLabel_10.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_10.gridx = 1;
		gbc_lblNewLabel_10.gridy = 11;
		contentPane.add(lblNewLabel_10, gbc_lblNewLabel_10);
		
		textField_7 = new JTextField();
		textField_7.setText(user.getSchool());
		GridBagConstraints gbc_textField_7 = new GridBagConstraints();
		gbc_textField_7.insets = new Insets(0, 0, 5, 5);
		gbc_textField_7.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_7.gridx = 2;
		gbc_textField_7.gridy = 11;
		contentPane.add(textField_7, gbc_textField_7);
		textField_7.setColumns(10);
		
		JLabel Label_11 = new JLabel("");
		GridBagConstraints gbc_Label_11 = new GridBagConstraints();
		gbc_Label_11.insets = new Insets(0, 0, 5, 0);
		gbc_Label_11.gridx = 3;
		gbc_Label_11.gridy = 11;
		contentPane.add(Label_11, gbc_Label_11);
		
		JLabel lblNewLabel_12 = new JLabel("学号");
		GridBagConstraints gbc_lblNewLabel_12 = new GridBagConstraints();
		gbc_lblNewLabel_12.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_12.gridx = 1;
		gbc_lblNewLabel_12.gridy = 12;
		contentPane.add(lblNewLabel_12, gbc_lblNewLabel_12);
		
		textField_8 = new JTextField();
		textField_8.setText(user.getSno());
		GridBagConstraints gbc_textField_8 = new GridBagConstraints();
		gbc_textField_8.insets = new Insets(0, 0, 5, 5);
		gbc_textField_8.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_8.gridx = 2;
		gbc_textField_8.gridy = 12;
		contentPane.add(textField_8, gbc_textField_8);
		textField_8.setColumns(10);
		
		JLabel Label_12 = new JLabel("");
		GridBagConstraints gbc_Label_12 = new GridBagConstraints();
		gbc_Label_12.insets = new Insets(0, 0, 5, 0);
		gbc_Label_12.gridx = 3;
		gbc_Label_12.gridy = 12;
		contentPane.add(Label_12, gbc_Label_12);
		
		JLabel lblNewLabel_13 = new JLabel("兴趣爱好");
		GridBagConstraints gbc_lblNewLabel_13 = new GridBagConstraints();
		gbc_lblNewLabel_13.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_13.gridx = 1;
		gbc_lblNewLabel_13.gridy = 13;
		contentPane.add(lblNewLabel_13, gbc_lblNewLabel_13);
		
		textField_9 = new JTextField();
		textField_9.setText(user.getIntrest());
		GridBagConstraints gbc_textField_9 = new GridBagConstraints();
		gbc_textField_9.insets = new Insets(0, 0, 5, 5);
		gbc_textField_9.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_9.gridx = 2;
		gbc_textField_9.gridy = 13;
		contentPane.add(textField_9, gbc_textField_9);
		textField_9.setColumns(10);
		
		JLabel Label_13 = new JLabel("");
		GridBagConstraints gbc_Label_13 = new GridBagConstraints();
		gbc_Label_13.insets = new Insets(0, 0, 5, 0);
		gbc_Label_13.gridx = 3;
		gbc_Label_13.gridy = 13;
		contentPane.add(Label_13, gbc_Label_13);
		
		JButton buttonFix = new JButton("确认修改");
		buttonFix.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String sql = "update user set address=? ,birth=? ,blood=? ,intrest=? ,name=? ,qq=? ,school=? ,sex=? ,sno=? where account=?";
				String email=textField_5.getText();
				String sex="";
				User u = new User();
				JDBCDAO jdao = new JDBCDAO();
				int i=0;
				if(bboy.isSelected()){
					sex="男";
				}else{
					sex="女";
				}
				//u.setAccount(Long.parseLong(textField.getText()));
				u.setAddress(textField_6.getText());  //jbao里面的泛型update没做好，这里暂时用处不大。
				u.setBirth(datePicker.getDate());
				u.setBlood(comboBox.getSelectedItem().toString());
				u.setIntrest(textField_9.getText());
				u.setName(textField_1.getText());
				//u.setPassword(String.valueOf(passwordField.getPassword()));
				u.setQq(textField_4.getText());
				u.setSchool(textField_7.getText());
				u.setSex(sex);
				
				u.setSno(textField_8.getText());
				System.out.println(Long.parseLong(textField.getText()));
				i=jdao.update(sql, new Object[]{u.getAddress(),u.getBirth(),u.getBlood(),u.getIntrest(),u.getName(),u.getQq(),u.getSchool(),u.getSex(),u.getSno(),Long.parseLong(textField.getText())});
				FixPersonDataFrame.this.setVisible(false);
			}
		});
		GridBagConstraints gbc_buttonFix = new GridBagConstraints();
		gbc_buttonFix.insets = new Insets(0, 0, 0, 5);
		gbc_buttonFix.gridx = 2;
		gbc_buttonFix.gridy = 14;
		contentPane.add(buttonFix, gbc_buttonFix);
	}
	private int getBloodIndex(String blood) {
		int i = 4;
		if(blood.equals("O")){
			i=0;
		}
		if(blood.equals("A")){
			i=1;
		}
		if(blood.equals("B")){
			i=2;
		}
		if(blood.equals("AB")){
			i=3;
		}
		return i;
	}
	public void init(){
		
	}

}
